package net.maku.propagate.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.propagate.convert.PropagateEducationConvert;
import net.maku.propagate.entity.PropagateEducationEntity;
import net.maku.propagate.service.PropagateEducationService;
import net.maku.propagate.query.PropagateEducationQuery;
import net.maku.propagate.vo.PropagateEducationVO;
import net.maku.system.service.SysOrgService;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 宣传教育
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-16
*/
@RestController
@RequestMapping("propagate/education")
@Tag(name="宣传教育")
@AllArgsConstructor
public class PropagateEducationController {
    private final PropagateEducationService propagateEducationService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('propagate:education:page')")
    public Result<PageResult<PropagateEducationVO>> page(@ParameterObject @Valid PropagateEducationQuery query){
        PageResult<PropagateEducationVO> page = propagateEducationService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('propagate:education:info')")
    public Result<PropagateEducationVO> get(@PathVariable("id") Long id){
        PropagateEducationEntity entity = propagateEducationService.getById(id);

        return Result.ok(PropagateEducationConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('propagate:education:save')")
    public Result<String> save(@RequestBody PropagateEducationVO vo){
        propagateEducationService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('propagate:education:update')")
    public Result<String> update(@RequestBody @Valid PropagateEducationVO vo){
        propagateEducationService.update(vo);

        return Result.ok();
    }

    @GetMapping("unmount/{id}/{status}")
    @Operation(summary = "上下架")
    @PreAuthorize("hasAuthority('propagate:education:unmount')")
    public Result<String> unmount(@PathVariable("id") Long id, @PathVariable("status") Integer status){
        propagateEducationService.unmount(id,status);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('propagate:education:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        propagateEducationService.delete(idList);

        return Result.ok();
    }
}